//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "CIISUpdatePS.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)


//---------------------------------------------------------------------------

__fastcall TCIISUpdatePS::TCIISUpdatePS( TUSBCANInterface * SetCAN,
																				 int SetCANAdr,
																				 int SetPSType,
																				 double SetAOut,
																				 double SetPSVOut,
																				 double SetPSIOut,
																				 bool SetPSOutputOn,
																				 bool SetPSRemote,
																				 int SetPSMode
																				)
{

	CAN = SetCAN;
	CANAdr = SetCANAdr;
	PSType = SetPSType;
	AOut = SetAOut;
	PSVOut = SetPSVOut;
	PSIOut = SetPSIOut;
	PSOutputOn = SetPSOutputOn;
	PSRemote = SetPSRemote;
	PSMode = SetPSMode;

	UPSState = 0;
	FUpdatePSReady = false;

}


__fastcall TCIISUpdatePS::~TCIISUpdatePS()
{

}

//---------------------------------------------------------------------------

void __fastcall TCIISUpdatePS::OnTimerEvent()
{

if( PSType == 11 )
	{
		switch (UPSState)
		{
			case 0 :
				CAN->SetAOut( CANAdr, AOut );
				UPSState = 1;
			break;
			case 1 :
				CAN->SetDigOut( CANAdr, 0, PSOutputOn );
				UPSState = 2;
			break;
			case 2 :
				CAN->SetDigOut( CANAdr, 1, PSRemote );
				UPSState = 3;
				FUpdatePSReady = true;
			break;
			case 3 :
				FUpdatePSReady = true;
			break;
		}

	}
else
	{
		switch (UPSState)
		{
			case 0 :
				CAN->SetPSVOut( CANAdr, PSVOut );
				UPSState = 1;
			break;
			case 1 :
				CAN->SetPSIOut( CANAdr, PSIOut );
				UPSState = 2;
			break;
			case 2 :
				CAN->SetPSMode( CANAdr, PSMode );
				UPSState = 3;
			break;
			case 3 :
				CAN->SetPSOutputOn( CANAdr, PSOutputOn );
				UPSState = 4;
				FUpdatePSReady = true;
			break;
			case 4 :
				FUpdatePSReady = true;
			break;
		}
	}
}




